package net.diaowen.common.utils;

import java.util.Map;

/**
 * ClassName:ResultJson
 * Package:net.diaowen.common.utils
 * Description:
 *
 * @date:2024/10/19 16:41
 * @author:lul
 */
public class ResultJson {
    /**
     * @escription 成功返回true，失败返回false
     */
    private boolean success;
    /**
     * @返回的附带信息，用于客户端提示给用户
     */
    private String message;
    /**
     * @返回的数据
     */
    private Map<String, Object> data;

    public ResultJson(){}

    public ResultJson(Map<String, Object> data, Boolean success, String message){
        this.success=success;
        this.message=message;
        if(data != null){
            this.data=data;
        }else{
            this.data=null;
        }
    }

    /**
     * 返回成功的请求
     * @param data 成功的数据
     * @param message 成功的提示
     * @return
     */
    public static ResultJson success(Map<String, Object> data,String message) {
        return new ResultJson(data,true, message);
    }

    /**
     * 返回成功的请求
     * @param data 成功的数据
     * @return
     */
    public static ResultJson success(Map<String, Object> data) {
        return new ResultJson(data,true, "请求成功！");
    }

    /**
     * 返回成功的请求
     * @param message 成功的提示
     * @return
     */
    public static ResultJson success(String message) {
        return new ResultJson(null,true, message);
    }

    /**
     * 返回失败的请求
     * @param message 失败的提示
     * @return
     */
    public static ResultJson fail(String message) {
        return new ResultJson(null,false, message);
    }

    public boolean isSuccess() {
        return success;
    }
    public void setSuccess(boolean success) {
        this.success = success;
    }
    public String getMessage() {
        return message;
    }
    public void setMessage(String message) {
        this.message = message;
    }
    public Map<String, Object> getData() {
        return data;
    }
    public void setData(Map<String, Object> data) {
        this.data = data;
    }
}